package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.project.system.domain.UserGiftDetail;
import com.happy.cat.project.system.service.IUserGiftDetailService;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 用户赠送礼物日志Controller
 *
 * @author verne
 * @date 2020-08-15
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userGiftDetail" )
@Api("用户赠送礼物日志 API")
public class UserGiftDetailController extends BaseController {

    private final IUserGiftDetailService iUserGiftDetailService;

    /**
     * 查询用户赠送礼物日志列表
     */
    @ApiOperation(value = "查询用户赠送礼物日志列表",notes = "查询用户赠送礼物日志列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userGiftDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserGiftDetail userGiftDetail)
    {
        startPage();
        LambdaQueryWrapper<UserGiftDetail> lqw = new LambdaQueryWrapper<UserGiftDetail>();
        if (userGiftDetail.getGiveId() != null){
            lqw.eq(UserGiftDetail::getGiveId ,userGiftDetail.getGiveId());
        }
        if (userGiftDetail.getReceiverId() != null){
            lqw.eq(UserGiftDetail::getReceiverId ,userGiftDetail.getReceiverId());
        }
        if (userGiftDetail.getGiftId() != null){
            lqw.eq(UserGiftDetail::getGiftId ,userGiftDetail.getGiftId());
        }
        List<UserGiftDetail> list = iUserGiftDetailService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户赠送礼物日志列表
     */
    @ApiOperation(value = "导出用户赠送礼物日志列表",notes = "导出用户赠送礼物日志列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userGiftDetail:export')" )
    @Log(title = "用户赠送礼物日志" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserGiftDetail userGiftDetail) {
        LambdaQueryWrapper<UserGiftDetail> lqw = new LambdaQueryWrapper<UserGiftDetail>(userGiftDetail);
        List<UserGiftDetail> list = iUserGiftDetailService.list(lqw);
        ExcelUtil<UserGiftDetail> util = new ExcelUtil<UserGiftDetail>(UserGiftDetail. class);
        return util.exportExcel(list, "userGiftDetail" );
    }

    /**
     * 获取用户赠送礼物日志详细信息
     */
    @ApiOperation(value = "获取用户赠送礼物日志详细信息",notes = "获取用户赠送礼物日志详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userGiftDetail:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserGiftDetailService.getById(id));
    }

    /**
     * 新增用户赠送礼物日志
     */
    @ApiOperation(value = "新增用户赠送礼物日志",notes = "新增用户赠送礼物日志",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userGiftDetail:add')" )
    @Log(title = "用户赠送礼物日志" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserGiftDetail userGiftDetail) {
        return toAjax(iUserGiftDetailService.save(userGiftDetail) ? 1 : 0);
    }

    /**
     * 修改用户赠送礼物日志
     */
    @ApiOperation(value = "修改用户赠送礼物日志",notes = "修改用户赠送礼物日志",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userGiftDetail:edit')" )
    @Log(title = "用户赠送礼物日志" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserGiftDetail userGiftDetail) {
        return toAjax(iUserGiftDetailService.updateById(userGiftDetail) ? 1 : 0);
    }

    /**
     * 删除用户赠送礼物日志
     */
    @ApiOperation(value = "删除用户赠送礼物日志",notes = "删除用户赠送礼物日志",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userGiftDetail:remove')" )
    @Log(title = "用户赠送礼物日志" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserGiftDetailService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
